use std::{io,cmp::Ordering};
use rand::Rng;

pub fn start() {
    println!("Guess the number!");

    let secret_number = rand::thread_rng().gen_range(0..=100);
    // println!("The secret number is: {secret_number}");
    loop {
        println!("Please input you guess!");

        let mut guess = String::new();

        io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");
        let guess:u32 = if let Ok(num) = guess.trim().parse() {
            num
        }else{
            println!("Please type a number!");
            continue
        };

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small"),
            Ordering::Greater => println!("Too big"),
            Ordering::Equal => {
                println!("You win");
                break;
            },
        }

        println!("You guess is {}!",guess);
    }
}
